﻿using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Web.Mvc;

namespace BoneSystem.Models
{
    [DataContract]
    public class JsonResultModel<T>
    {
        [DataMember]
        public T DataObject { get; set; }
        [DataMember]
        public IList<T> DataList { get; set; }
        [DataMember]
        public bool HasError { get; set; }
        [DataMember]
        public bool ShowMessage { get; set; }
        [DataMember]
        public string Message { get; set; }

        public static JsonResultModel<T> Fail(string message, bool showMessage = true)
        {
            return new JsonResultModel<T>()
            {
                HasError = true,
                Message = message,
                ShowMessage = showMessage
            };
        }
        public static JsonResultModel<T> Sucess()
        {
            return new JsonResultModel<T>();
        }

        public JsonResultModel()
        {
            ShowMessage = true;
            HasError = false;
        }

        public static string NotImplementedFunction()
        {
            return "Erro ao processar sua solicitação";
        }

        public static JsonResultModel<T> SendDataReturn(T entity,bool showMessage = false, string message ="")
        {
            return new JsonResultModel<T>()
            {
                DataObject = entity,
                ShowMessage = showMessage,
                Message = message
            };
        }
        public static JsonResultModel<T> SendDataReturnList(IList<T> entity,bool showMessage = false, string message ="")
        {
            return new JsonResultModel<T>()
            {
                DataList = entity,
                ShowMessage = showMessage,
                Message = message
            };
        }

    }
}